package embyparse.tokenizer;

import java.util.ArrayList;

import embyparse.util.TokenStream;

public class StringTokenizer implements TokenStream{

	ArrayList<Token> tokens;
	int currentline ;
	public StringTokenizer(int line, String s){
		tokens = new ArrayList<Token>();
		tokenizeLine(s);
		currentline = line;
	}


	private void tokenizeLine(String line){
		StringDummifier d = new StringDummifier();
		//System.out.println(line);
		line = d.dummify(line);
		//System.out.println(line);
		line = Tokenizer.presplit(line);
		//System.out.println(line);

		String[] splitted = line.split(" ");
		for(int i = 0; i<splitted.length; i++){
			if(splitted[i].length()>0){
				String token = d.dedummify(splitted[i]);
				if( !token.equals("\n")){
					token = token.replace("\n", "");
					tokens.add( new Token( token,currentline )  );
				}
			}
		}
		//System.out.println(tokens);
	}


	@Override
	public Token next() {
		if( tokens.size()>0){
			return tokens.remove(0);
		}
		return null;
	}


	@Override
	public boolean hasNext(){
		return (tokens.size()!=0);
	}


	@Override
	public void close() {
		tokens = new ArrayList<Token>();
	}
}
